package com.ouwen.smartpay.web;

import com.fm.core.common.enums.TranStatus;
import com.fm.core.utils.Ids;
import com.ouwen.smartpay.openapi.api.ServiceFacade;
import com.ouwen.smartpay.openapi.order.ServiceOrder;
import com.ouwen.smartpay.openapi.result.ServiceResult;
import com.ouwen.smartpay.utils.BeanUtil;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.Date;

/**
 *@author <a href="http://youngitman.tech">青年IT男</a>
 *@version v1.0.0
 *@className ApiServiceController
 *@description
 *@JunitTest: {@link  } 
 *@date 2020-04-29 15:33    
 *
 *
**/
@RestController
public class ApiServiceController {

    @Resource
    private ServiceFacade serviceFacade;

    @GetMapping("/pay")
    public String pay() throws Exception {
        ServiceOrder serviceOrder = new ServiceOrder();

        //请求头
        serviceOrder.setGid(Ids.gid());
        serviceOrder.setPartnerId("2222222222");
        serviceOrder.setSubPartnerId("333");
        serviceOrder.setService("pay");
        serviceOrder.setTimestamp(new Date());
        serviceOrder.setRequestNo(Ids.oid());
        serviceOrder.setNotifyUrl("http://127.0.0.1");

        ServiceOrder payOrder = new ServiceOrder();

        //业务参数order转换为map数据
        serviceOrder.setDatas(BeanUtil.transBean2Map(payOrder));

        ServiceResult result = serviceFacade.service(serviceOrder);


        if( result.getDatas() != null){
            Object o = result.getDatas().get("tranStatus");
            if(o!=null){
                TranStatus status = (TranStatus)o;
                return status.getCode();
            }else {
                return "fail";
            }
        }

        return "fail";

    }

}
